package com.sikaryofficial.workbench.config.handler.impl;

import com.sikaryofficial.workbench.config.handler.BusinessCodeStrategy;
import org.apache.ibatis.reflection.MetaObject;

import java.text.DecimalFormat;
import java.time.LocalDate;


/**
 * @author : wuweihong
 * @desc : 订单编码生成规则：年份+月份+订单序号
 * @date : 2024-09-30
 */

public class OrderCodeStrategy implements BusinessCodeStrategy {
 @Override
 public String generateCode(MetaObject metaObject) {
  String orderIdName = "orderHeaderId";
  long orderIdValue = (long) metaObject.getValue(orderIdName);
  LocalDate localDate = LocalDate.now();
  int currYear = localDate.getYear();
  int currMonth = localDate.getMonthValue();
  DecimalFormat df = new DecimalFormat("00");
  return currYear + "_" + df.format(currMonth) + "_" + orderIdValue;
 }
}
